package cn.db101.view;

import cn.db101.dao.bookDao;

import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class delete_book_Frame{
	JFrame jf=new JFrame() ;
	private JTextField textField;
	private JComboBox comboBox;
	

	/**
	 * Create the frame.
	 * @wbp.parser.entryPoint
	 */
	public void init() {
		jf.setTitle("删除图书");
		jf.setBounds(100, 100, 505, 653);
		
		JPanel panel = new JPanel();
		jf.getContentPane().add(panel, BorderLayout.CENTER);
		
		JPanel panel_1 = new JPanel();
		panel_1.setToolTipText("");
		panel_1.setForeground(new Color(0, 0, 0));
		panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "删除图书信息", TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0)));
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(delete_book_Frame.class.getResource("/img/x.jpg")));
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addComponent(lblNewLabel)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(27)
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 442, GroupLayout.PREFERRED_SIZE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 258, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 342, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(58, Short.MAX_VALUE))
		);
		
		JLabel label = new JLabel("删除\u65B9\u5F0F\uFF1A");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"按书名删除", "按书号删除", "按isbn号删除"}));
		
		JLabel label_1 = new JLabel("\u5173  \u952E  \u5B57\uFF1A");
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JButton button = new JButton("\u786E\u8BA4删除");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				deleteAction(e);
			}
		});
		button.setIcon(new ImageIcon(delete_book_Frame.class.getResource("/icon/trash删除.png")));
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGap(103)
							.addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING)
								.addComponent(label)
								.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE))
							.addGap(32)
							.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
								.addComponent(textField)
								.addComponent(comboBox, 0, 100, Short.MAX_VALUE)))
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGap(152)
							.addComponent(button)))
					.addContainerGap(101, Short.MAX_VALUE))
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(47)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(label))
					.addGap(54)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
					.addGap(72)
					.addComponent(button, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
					.addGap(56))
		);
		panel_1.setLayout(gl_panel_1);
		panel.setLayout(gl_panel);
		//设置窗体是否可改变
		jf.setResizable(false);
		//设置窗体可见
		jf.setVisible(true);	
		//设置JFrame居中显示
		jf.setLocationRelativeTo(null);

	}


	protected void deleteAction(ActionEvent e) {
		// TODO Auto-generated method stub
		int index = comboBox.getSelectedIndex();
		String string = textField.getText().toString();
		if(string.equals("")||string==null) {
			JOptionPane.showMessageDialog(null, "请输入条件!");
			return;
		}
		
		int result = JOptionPane.showConfirmDialog(null, "是否删除", "提示",JOptionPane.YES_NO_OPTION);
		if(result==JOptionPane.YES_OPTION){
				new bookDao().deleteBook(index, string);
				JOptionPane.showMessageDialog(null, "删除成功");
		}else{
			return;
		}
	}
	
	public static void main(String[] args) {
		new delete_book_Frame().init();
	}
}
